param ( [switch]$noPrompt )

if (-not $noPSCPrompt)
{
	function prompt
	{
		Get-Location | Write-Host -ForegroundColor Yellow
		"> "
	}
}

#This function adds the full path of a script to the $env:path. This is like a environment variable
#which can contain multiple full path refernces seperated by a semicolon.
function AddTo-Path
{
  param 
  (
    [string] $path,
    [switch] $End
  )
  
  $PathEntries = $Env:Path.split(";")
  $fullPath = Get-FullPath $path
  foreach($entry in $PathEntries)
  {
    if ($entry -eq $fullPath) {return}
  }
  
  if ($end)
  {
    $Env:Path += ";$fullPath"
  }
  else
  {
    $Env:Path = "$fullPath;" + $Env:Path
  } 
}

function Get-ScriptDir
{
	$CallingInvocation = Get-Variable -scope 0 myinvocation
	$ScriptName = $CallingInvocation.Value.ScriptName
	if ($ScriptName -ne $null -and $ScriptName -ne "")
	{
	  $scriptPath = Split-Path -Parent $CallingInvocation.Value.ScriptName
	}
	else
	{
		$scriptPath =[string] (get-location)
	}
	$scriptPath
}

function Get-FullPath ([string] $path)
{
	[System.IO.Path]::GetFullPath($path)
}

function Init-Scripts ([string] $InitScriptDir, $excludePattern='_.*\.ps1', [switch]$recurse = $TRUE)
{
	[array] $_psfiles = dir $InitScriptDir -filter *.ps1 -recurse:$recurse | where {$_.Name -notmatch $excludePattern}
	if ($_psfiles)
	{
		foreach ($_file in $_psfiles)
		{
			. $_file.fullname
		}
	}
}

# initilize any custom scripts in the root of the install folder
 . Init-Scripts (Get-ScriptDir) -recurse:$FALSE

# make scripts available as cmdlets in the \PSC_BnD\CmdLets dir
 $cmdlets = Get-FullPath "..\CmdLets"
 AddTo-Path $cmdlets

